﻿using UnityEngine;

namespace AI.Graph {


    public abstract class SubState : SubNode {

#region Fields

        private static NodeColors s_colors = new NodeColors (new Color32 (0, 185, 165, 255), new Color32 (0, 90, 85, 255), new Color32 (0, 65, 60, 255));

        [SerializeField, HideInInspector]
        [Port (Direction.Input, Capacity.Multi, "Input", typeof (SubCondition), typeof (State))]
        private ConnectionPort m_input = null;

#endregion


#region Properties

        internal override NodeColors colors {
            get { return s_colors; }
        }

        internal ConnectionPort input {
            get { return m_input; }
        }

#endregion


        [SerializeField, HideInInspector]
        internal ActiveTimer activeTimer = new ActiveTimer ();


        /// <summary>
        /// Execute this SubState.
        /// </summary>
        /// <param name="aiBehaviour">The connected AIBehaviour.</param>
        internal void Perform (AIBehaviour aiBehaviour) {
            aiBehaviour.Log (this, $"Perform");
            activeTimer.SetActive ();
            OnPerform (aiBehaviour);
        }


        /// <summary>
        /// Is called if this SubState needs to be executed.  
        /// </summary>
        /// <param name="aiBehaviour">The connected AIBehaviour.</param>
        protected abstract void OnPerform (AIBehaviour aiBehaviour);


        /// <summary>
        /// Deep clone with the given original Node.
        /// </summary>
        internal override void Copy (AIControllerSerializer serializer, Node originalNode) {
            base.Copy (serializer, originalNode);
            SubState original = (SubState) originalNode;

            m_input = serializer.GetCopyOf (original.m_input);
        }

    }


}